package Test.限流算法;

/**
 * @Author: kirito
 * @Date: 2025/3/11 19:38
 * @Description:
 * 请求进来判断当前时间减去上次滑动窗口左界限
 *      如果大于窗口大小，更新时间，重置窗口计数
 *
 * 判断count是否大于阈值
 */

public class 固定窗口test {
    private int count = 0;
    private long windowLimit = 1000L;
    private int countLimit = 10;
    private long lastTime = 0L;
    private long currentTime = 0L;

    private boolean func() {
        currentTime = System.currentTimeMillis();
        if (currentTime - lastTime > windowLimit) {
            lastTime = currentTime;
            count = 0;
        }
        if (count < countLimit) {
            count++;
            return true;
        }
        return false;
    }

}
